package com.example.musicproject_b.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.b_pojo.Musicuser;
import com.example.common.pojo.musicuser;
import com.example.common.utils.Resultb;
import com.example.service.MusicUserservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/B_admin/musicuser")
public class BMusicUserController {

    @Autowired
    private MusicUserservice musicUserservice;

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 15:54
     * 管理员列表（包括逻辑删除）
     *
     */
    @RequestMapping("/hasdelectlist")
    public Resultb hasdelectlist(int pageNum, int pageSize) {
        Page<Musicuser> gethasdeletelist = musicUserservice.gethasdeletelist(pageNum, pageSize);
        if (gethasdeletelist != null){
            return Resultb.success(gethasdeletelist);
        }
        return Resultb.error();
    }



    /**
     * @return 
     * @param @param null
     * @author znk
     * @date 2024/9/11 15:54
     * 管理员列表（不包括逻辑删除）
     */
    @RequestMapping("/alllist")
    public Resultb alllist(int pageNum, int pageSize) {
        Page<Musicuser> alllist = musicUserservice.getAlllist(pageNum, pageSize);
        if(alllist != null){
            return Resultb.success(alllist);
        }
        return Resultb.error();
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 16:01
     * 根据名称查询用户（不包括逻辑删除）
     */
    @RequestMapping("/getuserByName")
    public Resultb getuserByName(String username) {
        Musicuser userByName = musicUserservice.getuserByName(username);
        if (userByName != null){
            return Resultb.success(userByName);
        }
        if (userByName == null){
            return Resultb.error("用户不存在！");
        }
        return Resultb.error();
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 16:03
     * 根据id查询用户(包括逻辑删除)
     */
    @RequestMapping("/getuserById")
    public Resultb getuserById(Long id) {
        Musicuser userById = musicUserservice.getuserById(id);
        if (userById != null){
            return Resultb.success(userById);
        }
        if (userById == null){
            return Resultb.error("用户不存在！");
        }
        return Resultb.error();
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 15:57
     * 修改用户信息(包含逻辑删除)
     */
    @RequestMapping("/updateuser")
    public Resultb updateuser(@RequestBody Musicuser musicuser) {
        boolean b = musicUserservice.b_updateById(musicuser);
        if (b){
            return Resultb.success();
        }
        return Resultb.error();
    }


    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 15:57
     * 禁用和启用用户
     */
    @RequestMapping("/startstopuser")
    public Resultb startstopeuser(Long id) {
        boolean b = musicUserservice.startRoleByRoleId(id);
        if (b){
            return Resultb.success("状态修改成功");
        }
        return Resultb.error();
    }

    /**
     * @return
     * @param @param null
     * @author znk
     * @date 2024/9/11 15:57
     * 彻底删除用户
     */
    @RequestMapping("/deleteuser")
    public Resultb deleteuser(Long id) {
        boolean b = musicUserservice.deleteUser(id);
        if (b){
            return Resultb.success("删除成功");
        }
        return Resultb.error();
    }

}
